package cn.edu.scau.cmi.liyunlin.spring;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import cn.edu.scau.cmi.liyunlin.spring.domain.Student;
import cn.edu.scau.cmi.liyunlin.spring.domain.Teacher;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.TextArea;

public class SpringViewController {
	@FXML
	private Button getStuObj;
	@FXML
	private Button getTeaObj;
	@FXML
	private TextArea output;
	
	//ApplicationContext applicationContext;
	
	public void studentEvent() {
		ApplicationContext applicationContext = getApplicationContext1();
		Student student = (Student)applicationContext.getBean("zhangsan");
		output.appendText(student.toString()+"\n");
	}
	
	public void teacherEvent() {
		ApplicationContext applicationContext = getApplicationContext1();
		Teacher teacher = (Teacher)applicationContext.getBean("liangzaoqing");
		output.appendText(teacher.toString()+"\n");
	}
	
	private static ApplicationContext getApplicationContext1() {
		ApplicationContext ac1 = new ClassPathXmlApplicationContext("applicationContext.xml");

		return ac1;
	}
}
